package com.reebake.ideal.verify.code.config;

import com.reebake.ideal.verify.code.core.VerifyCodeGenerator;
import com.reebake.ideal.verify.code.core.VerifyCodeService;
import com.reebake.ideal.verify.code.core.VerifyCodeStorage;
import com.reebake.ideal.verify.code.handler.DefaultVerifyCodeService;
import com.reebake.ideal.verify.code.handler.DefaultVerifyCodeStorage;
import com.reebake.ideal.verify.code.properties.VerifyCodeProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(VerifyCodeProperties.class)
public class VerifyCodeAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    VerifyCodeGenerator verifyCodeGenerator(VerifyCodeProperties verifyCodeProperties) {
        return new VerifyCodeGenerator(verifyCodeProperties);
    }

    @Bean
    @ConditionalOnMissingBean
    VerifyCodeStorage verifyCodeStorage() {
        return new DefaultVerifyCodeStorage();
    }

    @Bean
    @ConditionalOnMissingBean
    VerifyCodeService verifyCodeService() {
        return new DefaultVerifyCodeService();
    }
}
